<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理员管理</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 搜索 -->
        <el-form :inline="true" style="margin-top: 20px;">
            <el-form-item>
                <el-button size="small" @click="exportExcel">导出Excel</el-button>
            </el-form-item>
            <el-form-item>
                <el-input size="small" v-model="username" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item>
                <el-input size="small" v-model="mobile" placeholder="请输入手机号"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            </el-form-item>
            <el-form-item>
                <el-button size="small" type="primary" icon="el-icon-search" @click="chongzhi">重置</el-button>
            </el-form-item>
            <el-form-item>
                <el-button size="small" type="primary" icon="el-icon-plus" @click="openAdmin()">添加</el-button>
            </el-form-item>
        </el-form>

        <!-- 列表 -->
        <el-table size="small" ref="multipleTable" :data="DataList" element-loading-text="拼命加载中" style="width: 100%;"
            v-horizontal-scroll>
            <el-table-column align="center" sortable type="index" label="序号"></el-table-column>
            <el-table-column align="center" sortable prop="username" label="用户名" width="150"></el-table-column>
            <el-table-column align="center" sortable prop="password" label="密码" width="150"></el-table-column>
            <el-table-column align="center" sortable prop="name" label="姓名" width="140"></el-table-column>
            <el-table-column align="center" sortable prop="mobile" label="手机号" width="200"></el-table-column>
            <el-table-column align="center" sortable prop="sex" label="性别" width="150"></el-table-column>
            <!-- <el-table-column align="center" sortable prop="menuOne" label="一级菜单密码" width="150"></el-table-column> -->
            <el-table-column align="center" sortable prop="menuTwo" label="二级菜单密码" width="150"></el-table-column>
            <el-table-column align="center" sortable prop="createTime" label="创建时间" width="150">
                <template slot-scope="scope">
                    <div>{{ transformDate(scope.row.createTime) }}</div>
                </template>
            </el-table-column>
            <el-table-column align="center" sortable prop="updateTime" label="更新时间" width="150">
                <template slot-scope="scope">
                    <div>{{ transformDate(scope.row.updateTime) }}</div>
                </template>
            </el-table-column>
            <el-table-column align="center" label="操作" width="300" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="primary" @click="openAdminBq(scope.row)">编辑标签</el-button>
                    <el-button size="mini" type="primary" @click="openAdmin(scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="deleAdmin(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 编辑界面 -->
        <el-dialog :title="tit" :visible.sync="editFormVisiible" width="50%">
            <el-form label-width="100px">
                <el-form-item label="用户名">
                    <el-input size="small" v-model="xiugai.username" auto-complete="off" placeholder="请输入用户名"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input size="small" v-model="xiugai.password" auto-complete="off" placeholder="请输入密码"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input size="small" v-model="xiugai.name" auto-complete="off" placeholder="请输入姓名"></el-input>
                </el-form-item>
                <el-form-item label="手机号">
                    <el-input size="small" v-model="xiugai.mobile" auto-complete="off" placeholder="请输入手机号"></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-input size="small" v-model="xiugai.sex" auto-complete="off" placeholder="请输入性别"></el-input>
                </el-form-item>
                <!-- <el-form-item label="一级菜单密码">
                    <el-input size="small" v-model="xiugai.menuOne" auto-complete="off"
                        placeholder="请输入一级菜单密码"></el-input>
                </el-form-item> -->
                <el-form-item label="二级菜单密码">
                    <el-input size="small" v-model="xiugai.menuTwo" auto-complete="off" placeholder="请输入二级菜单密码"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button size="small" @click='closeDialog()'>取消</el-button>
                <el-button size="small" type="primary" :loading="loading" @click="addData()"
                    v-if="tit == '添加'">添加</el-button>
                <el-button size="small" type="primary" :loading="loading" @click="upData()"
                    v-if="tit == '修改'">修改</el-button>
            </div>
        </el-dialog>

        <!-- 编辑标签界面 -->
        <el-dialog title="添加标签" :visible.sync="editFormVisiibleBq" width="50%">
            <el-tree :data="data" show-checkbox node-key="menuid" :props="defaultProps" ref="tree">
            </el-tree>
            <div slot="footer" class="dialog-footer">
                <el-button size="small" @click='closeDialogBq()'>取消</el-button>
                <el-button size="small" type="primary" :loading="loading" @click="addDataBq()">确定</el-button>
            </div>
        </el-dialog>
        <!-- 分页组件 -->
        <!-- <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination> -->
    </div>
</template>

<script>
import {
    getAdminList,
    addAdmin,
    deleteAdmin,
    upAdmin
} from "../../api/userMG";
import * as XLSX from 'xlsx';
import { saveAs } from 'file-saver';
import Pagination from '../../components/Pagination'
export default {
    data() {
        return {
            DataList: [],
            loading: false,
            username: '',
            mobile: '',
            xiugai: {
                username: '',
                password: '',
                name: '',
                mobile: '',
                sex: '',
                menuOne: '',
                menuTwo: '',
                createTime: '',
                updateTime: ''
            },
            editFormVisiible: false,
            tit: '添加',
            // 分页参数
            pageparm: {
                currentPage: 1,
                pageSize: 20,
                total: 10
            },
            data: [{
                menuid: 1,
                icon: 'li-icon-xiangmuguanli',
                menuname: '首页',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 11,
                        icon: 'icon-cat-skuQuery',
                        menuname: '首页',
                        hasThird: 'N',
                        url: 'index/Index',
                        menus: null,
                    },
                    {
                        menuid: 12,
                        icon: 'icon-cat-skuQuery',
                        menuname: '数据统计',
                        hasThird: 'N',
                        url: 'index/DataStatistics',
                        menus: null
                    }
                ],
            },
            {
                menuid: 2,
                icon: 'li-icon-xiangmuguanli',
                menuname: '用户管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 21,
                        icon: 'icon-cat-skuQuery',
                        menuname: '用户列表',
                        hasThird: 'N',
                        url: 'user/User',
                        menus: null
                    }
                ]
            },
            {
                menuid: 3,
                icon: 'li-icon-xiangmuguanli',
                menuname: '合伙人管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 31,
                        icon: 'icon-cat-skuQuery',
                        menuname: '合伙人列表',
                        hasThird: 'N',
                        url: 'partner/Partner',
                        menus: null
                    },
                    {
                        menuid: 32,
                        icon: 'icon-cat-skuQuery',
                        menuname: '合伙人申请列表',
                        hasThird: 'N',
                        url: 'partner/PartnerApplication',
                        menus: null
                    }
                ]
            },
            {
                menuid: 4,
                icon: 'li-icon-xiangmuguanli',
                menuname: '充电桩管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 41,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充电桩管理',
                        hasThird: 'N',
                        url: 'chargingStation/ElectricPile',
                        menus: null
                    },
                    {
                        menuid: 42,
                        icon: 'icon-cat-skuQuery',
                        menuname: '站点管理',
                        hasThird: 'N',
                        url: 'chargingStation/Site',
                        menus: null
                    },
                    {
                        menuid: 43,
                        icon: 'icon-cat-skuQuery',
                        menuname: '端口管理',
                        hasThird: 'N',
                        url: 'chargingStation/Port',
                        menus: null
                    },
                    {
                        menuid: 44,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充电桩订单管理',
                        hasThird: 'N',
                        url: 'chargingStation/OrderForGoods',
                        menus: null
                    },
                    {
                        menuid: 45,
                        icon: 'icon-cat-skuQuery',
                        menuname: '警告管理',
                        hasThird: 'N',
                        url: 'chargingStation/Warn',
                        menus: null
                    },
                    {
                        menuid: 46,
                        icon: 'icon-cat-skuQuery',
                        menuname: '余额充电金额终止条件',
                        hasThird: 'N',
                        url: 'chargingStation/Termination',
                        menus: null
                    },
                ]
            },
            {
                menuid: 16,
                icon: 'li-icon-xiangmuguanli',
                menuname: '管理员充电桩管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 161,
                        icon: 'icon-cat-skuQuery',
                        menuname: '管理员充电桩列表',
                        hasThird: 'N',
                        url: 'adminCharging/AdminElctricPile',
                        menus: null
                    },
                    {
                        menuid: 162,
                        icon: 'icon-cat-skuQuery',
                        menuname: '管理员站点列表',
                        hasThird: 'N',
                        url: 'adminCharging/AdminSite',
                        menus: null
                    },
                    {
                        menuid: 163,
                        icon: 'icon-cat-skuQuery',
                        menuname: '管理员端口列表',
                        hasThird: 'N',
                        url: 'adminCharging/AdminPort',
                        menus: null
                    },
                ]
            },
            {
                menuid: 5,
                icon: 'li-icon-xiangmuguanli',
                menuname: '发票管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 51,
                        icon: 'icon-cat-skuQuery',
                        menuname: '发票列表',
                        hasThird: 'N',
                        url: 'invoice/Invoice',
                        menus: null
                    }
                ]
            },
            {
                menuid: 6,
                icon: 'li-icon-xiangmuguanli',
                menuname: '商品管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 61,
                        icon: 'icon-cat-skuQuery',
                        menuname: '商品分类列表',
                        hasThird: 'N',
                        url: 'commodity/Category',
                        menus: null
                    },
                    {
                        menuid: 62,
                        icon: 'icon-cat-skuQuery',
                        menuname: '商品列表',
                        hasThird: 'N',
                        url: 'commodity/Commodity',
                        menus: null
                    },
                    {
                        menuid: 63,
                        icon: 'icon-cat-skuQuery',
                        menuname: '订单列表',
                        hasThird: 'N',
                        url: 'commodity/ProductOrders',
                        menus: null
                    },
                    {
                        menuid: 64,
                        icon: 'icon-cat-skuQuery',
                        menuname: '评论列表',
                        hasThird: 'N',
                        url: 'commodity/Comment',
                        menus: null
                    },
                ]
            },
            {
                menuid: 13,
                icon: 'li-icon-xiangmuguanli',
                menuname: '优惠券管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 131,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充电桩优惠券',
                        hasThird: 'N',
                        url: 'coupon/FullReduction',
                        menus: null
                    },
                    {
                        menuid: 132,
                        icon: 'icon-cat-skuQuery',
                        menuname: '商城优惠券',
                        hasThird: 'N',
                        url: 'coupon/MallCoupons',
                        menus: null
                    },
                    {
                        menuid: 133,
                        icon: 'icon-cat-skuQuery',
                        menuname: '活动优惠券',
                        hasThird: 'N',
                        url: 'coupon/EventCoupons',
                        menus: null
                    },
                    {
                        menuid: 134,
                        icon: 'icon-cat-skuQuery',
                        menuname: '注册赠送优惠券',
                        hasThird: 'N',
                        url: 'coupon/GiftCoupons',
                        menus: null
                    },
                ]
            },
            {
                menuid: 7,
                icon: 'li-icon-xiangmuguanli',
                menuname: '财务管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 71,
                        icon: 'icon-cat-skuQuery',
                        menuname: '积分管理',
                        hasThird: 'N',
                        url: 'finance/Integral',
                        menus: null
                    },
                    {
                        menuid: 77,
                        icon: 'icon-cat-skuQuery',
                        menuname: '消费反积分百分比管理',
                        hasThird: 'N',
                        url: 'finance/Consumption',
                        menus: null,
                        pwd: 123,
                    },
                    {
                        menuid: 72,
                        icon: 'icon-cat-skuQuery',
                        menuname: '钱包管理',
                        hasThird: 'N',
                        url: 'finance/Wallet',
                        menus: null
                    },
                    {
                        menuid: 73,
                        icon: 'icon-cat-skuQuery',
                        menuname: '提现管理',
                        hasThird: 'N',
                        url: 'finance/CashWithdrawal',
                        menus: null
                    },
                    {
                        menuid: 78,
                        icon: 'icon-cat-skuQuery',
                        menuname: '提现税率管理',
                        hasThird: 'N',
                        url: 'finance/TaxRate',
                        menus: null
                    },
                    {
                        menuid: 74,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充值记录',
                        hasThird: 'N',
                        url: 'finance/RechargeRecords',
                        menus: null
                    },
                    {
                        menuid: 75,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充值金额设置',
                        hasThird: 'N',
                        url: 'finance/RechargeAmount',
                        menus: null
                    },
                    {
                        menuid: 76,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充值积分百分比管理',
                        hasThird: 'N',
                        url: 'finance/RechargePoints',
                        menus: null
                    },
                ]
            },
            {
                menuid: 8,
                icon: 'li-icon-xiangmuguanli',
                menuname: '会员配置管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 81,
                        icon: 'icon-cat-skuQuery',
                        menuname: '会员配置列表',
                        hasThird: 'N',
                        url: 'member/Member',
                        menus: null
                    }, {
                        menuid: 111,
                        icon: 'icon-cat-skuQuery',
                        menuname: '复购佣金设置',
                        hasThird: 'P',
                        url: 'laxin/Laxin',
                        menus: null
                    },
                    {
                        menuid: 82,
                        icon: 'icon-cat-skuQuery',
                        menuname: '税金设置',
                        hasThird: 'N',
                        url: 'member/Taxes',
                        menus: null
                    },
                ]
            },
            {
                menuid: 9,
                icon: 'li-icon-xiangmuguanli',
                menuname: '设备管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 91,
                        icon: 'icon-cat-skuQuery',
                        menuname: '设备列表',
                        hasThird: 'N',
                        url: 'device/Device',
                        menus: null
                    }
                ]
            },
            {
                menuid: 10,
                icon: 'li-icon-xiangmuguanli',
                menuname: '用户反馈',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 101,
                        icon: 'icon-cat-skuQuery',
                        menuname: '用户反馈列表',
                        hasThird: 'N',
                        url: 'feedback/Feedback',
                        menus: null
                    },
                ]
            },
            {
                menuid: 15,
                icon: 'li-icon-xiangmuguanli',
                menuname: '转让管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 151,
                        icon: 'icon-cat-skuQuery',
                        menuname: '充电桩转让列表',
                        hasThird: 'P',
                        url: 'transferReview/TransferReview',
                        menus: null
                    },
                    {
                        menuid: 152,
                        icon: 'icon-cat-skuQuery',
                        menuname: '场地转让列表',
                        hasThird: 'P',
                        url: 'transferReview/TransferReviewCD',
                        menus: null
                    },
                    {
                        menuid: 153,
                        icon: 'icon-cat-skuQuery',
                        menuname: '转让手续费设置管理',
                        hasThird: 'P',
                        url: 'transference/Transference',
                        menus: null
                    },
                ]
            },
            {
                menuid: 20,
                icon: 'li-icon-xiangmuguanli',
                menuname: '排行榜管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 201,
                        icon: 'icon-cat-skuQuery',
                        menuname: '减碳达人排行榜管理',
                        hasThird: 'N',
                        url: 'charts/CarbonReduction',
                        menus: null
                    },
                    {
                        menuid: 202,
                        icon: 'icon-cat-skuQuery',
                        menuname: '明日之星排行榜管理',
                        hasThird: 'N',
                        url: 'charts/Stars',
                        menus: null
                    },
                ]
            },
            {
                menuid: 14,
                icon: 'li-icon-xiangmuguanli',
                menuname: '平台管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 141,
                        icon: 'icon-cat-skuQuery',
                        menuname: '轮播图列表',
                        hasThird: 'N',
                        url: 'terrace/Carousel',
                        menus: null
                    },
                    {
                        menuid: 142,
                        icon: 'icon-cat-skuQuery',
                        menuname: '协议列表',
                        hasThird: 'N',
                        url: 'terrace/Agreement',
                        menus: null
                    },
                ]
            },
            {
                menuid: 21,
                icon: 'li-icon-xiangmuguanli',
                menuname: '管理员管理',
                hasThird: null,
                url: null,
                menus: [
                    {
                        menuid: 211,
                        icon: 'icon-cat-skuQuery',
                        menuname: '管理员',
                        hasThird: 'N',
                        url: 'administrators/Administrators',
                        menus: null
                    }
                ]
            },],
            defaultProps: {
                children: 'menus',
                label: 'menuname'
            },
            biaoqian: {},
            editFormVisiibleBq: false,
            defaultCheckedKeys: [],
            // checkedKeys: []
        }
    },
    // 注册组件
    components: {
        Pagination
    },
    created() {
        this.getdata(1)
    },
    mounted() {

    },
    methods: {
        addDataBq() {
            // 将之前被选中的数据改变为false
            this.data.forEach((item) => {
                item.menus.forEach((child) => {
                    if (item.select || child.select) {
                        item.select = false;
                        child.select = false;
                    }
                });
            });
            // 获取新一轮所有选中的节点
            const checkedNodes = this.$refs.tree.getCheckedNodes();
            this.data.map((item) => {
                item.menus.map((child) => {
                    let exists = checkedNodes.filter((sel) => sel.menuname == child.menuname);
                    if (exists.length > 0) {
                        item.select = true;
                        child.select = true;
                    }
                });
            });
            let arr = [];
            this.data.map((item) => {
                if (item.select) {
                    let node = {};
                    node.menuid = item.menuid;
                    node.icon = item.icon;
                    node.menuname = item.menuname;
                    node.menus = [];
                    item.menus.map((child) => {
                        if (child.select) {
                            node.menus.push(child);
                        }
                    });
                    arr.push(node);
                }
            })
            const jsonData = JSON.stringify(arr);
            console.log(jsonData);
            this.biaoqian.menuIds = jsonData
            upAdmin(this.biaoqian).then((res) => {
                this.loading = false;
                if (res.code == 200) {
                    this.editFormVisiibleBq = false;
                    this.$message.success(res.msg)
                    this.getdata(this.pageparm.currentPage)
                } else {
                    this.editFormVisiibleBq = false;
                    this.$message.error(res.msg);
                }
            })
            this.defaultCheckedKeys = []
            this.$refs.tree.setCheckedKeys([]);
        },
        // 关闭编辑对话框
        closeDialogBq() {
            this.defaultCheckedKeys = []
            this.editFormVisiibleBq = false
            this.$refs.tree.setCheckedKeys([])
            this.$message({
                type: 'info',
                message: '已取消编辑'
            })
        },

        // 打开标签编辑器
        openAdminBq(row) {
            var userdata = JSON.parse(localStorage.getItem("userdata"))
            this.$prompt('请输入密码', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^(?!(\s+$))/,
                inputErrorMessage: '不可以空数据提交!'
            }).then(({ value }) => {
                if (value === userdata.menuTwo) {
                    this.biaoqian.id = row.id
                    this.biaoqian.username = row.username
                    this.biaoqian.password = row.password
                    this.biaoqian.name = row.name
                    this.biaoqian.mobile = row.mobile
                    this.biaoqian.sex = row.sex
                    this.biaoqian.menuOne = row.menuOne
                    this.biaoqian.menuTwo = row.menuTwo
                    if (row.menuIds !== '"[]"' && row.menuIds !== null) {
                        setTimeout(() => {
                            this.defaultCheckedKeys = []
                            this.biaoqian.menuIds = JSON.parse(row.menuIds)
                            this.biaoqian.menuIds.forEach((item) => {
                                item.menus.forEach((child) => {
                                    this.defaultCheckedKeys.push(item.menuid)
                                    this.defaultCheckedKeys.push(child.menuid)
                                });
                            });
                            this.$nextTick(() => {
                                this.$refs.tree.setCheckedKeys(this.defaultCheckedKeys);
                            });
                        }, 1);
                    } else {
                        setTimeout(() => {
                            this.defaultCheckedKeys = []
                            this.$nextTick(() => {
                                this.$refs.tree.setCheckedKeys(this.defaultCheckedKeys);
                            });
                        }, 1);
                    }
                    this.biaoqian.createTime = row.createTime
                    this.biaoqian.updateTime = row.updateTime
                    this.editFormVisiibleBq = true;
                } else {
                    this.$message({
                        type: 'error',
                        message: '密码错误'
                    });
                }
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });
        },
        // 分页插件事件
        callFather(parm) {
            this.pageparm.page = parm.currentPage
            this.getdata(parm.currentPage)
        },
        exportExcel() {
            //转换成excel时，使用原始的格式
            var xlsxParam = { raw: true };
            let fix = document.querySelector(".el-table__fixed-right");
            let wb;
            //判断有无fixed定位，如果有的话去掉，后面再加上，不然数据会重复
            if (fix) {
                wb = XLSX.utils.table_to_book(
                    this.$refs.multipleTable.$el.removeChild(fix), xlsxParam
                );
                this.$refs.multipleTable.$el.appendChild(fix);
            } else {
                wb = XLSX.utils.table_to_book(this.$refs.multipleTable.$el, xlsxParam);
            }
            var wbout = XLSX.write(wb, {
                bookType: "xls",
                bookSST: true,
                type: "array",
            });
            try {
                // 如果是IE浏览器，使用Blob通过navigator.msSaveBlob保存
                if (navigator.msSaveBlob) {
                    navigator.msSaveBlob(new Blob([wbout], { type: 'application/octet-stream' }), '管理员列表.xlsx');
                } else {
                    // 在其他浏览器中使用file-saver保存文件
                    saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '管理员列表.xlsx');
                }
            } catch (e) {
                if (typeof console !== 'undefined') console.log(e, wbout);
            }
            return wbout;
        },
        // 修改
        upData() {
            this.loading = true
            upAdmin(this.xiugai).then((res) => {
                this.loading = false;
                if (res.code == 200) {
                    this.editFormVisiible = false
                    this.$message.success(res.msg)
                    this.getdata(this.pageparm.currentPage)
                } else {
                    this.editFormVisiible = false
                    this.$message.error(res.msg);
                }
            })
        },
        // 添加
        addData() {
            this.loading = true
            addAdmin(this.xiugai).then((res) => {
                this.loading = false;
                if (res.code == 200) {
                    this.editFormVisiible = false
                    this.$message.success(res.msg)
                    this.getdata(this.pageparm.currentPage)
                } else {
                    this.editFormVisiible = false
                    this.$message.error(res.msg);
                }
            })
        },
        // 关闭编辑对话框
        closeDialog() {
            this.editFormVisiible = false
            this.$message({
                type: 'info',
                message: '已取消编辑'
            })
        },
        // 打开编辑器
        openAdmin(row) {
            var userdata = JSON.parse(localStorage.getItem("userdata"))
            this.$prompt('请输入密码', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^(?!(\s+$))/,
                inputErrorMessage: '不可以空数据提交!'
            }).then(({ value }) => {
                if (value === userdata.menuTwo) {
                    this.editFormVisiible = true;
                    if (row != undefined && row != "undefined") {
                        this.tit = "修改"
                        this.xiugai.id = row.id
                        this.xiugai.username = row.username
                        this.xiugai.password = row.password
                        this.xiugai.name = row.name
                        this.xiugai.mobile = row.mobile
                        this.xiugai.sex = row.sex
                        this.xiugai.menuOne = row.menuOne
                        this.xiugai.menuTwo = row.menuTwo
                        this.xiugai.createTime = row.createTime
                        this.xiugai.updateTime = row.updateTime
                    } else {
                        this.tit = "添加";
                        this.xiugai.id = ''
                        this.xiugai.username = ''
                        this.xiugai.password = ''
                        this.xiugai.name = ''
                        this.xiugai.mobile = ''
                        this.xiugai.sex = ''
                        this.xiugai.menuOne = ''
                        this.xiugai.menuTwo = ''
                        this.xiugai.createTime = ''
                        this.xiugai.updateTime = ''
                    }
                } else {
                    this.$message({
                        type: 'error',
                        message: '密码错误'
                    });
                }
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });
        },
        // 删除
        deleAdmin(row) {
            var userdata = JSON.parse(localStorage.getItem("userdata"))
            this.$prompt('请输入密码', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^(?!(\s+$))/,
                inputErrorMessage: '不可以空数据提交!'
            }).then(({ value }) => {
                if (value === userdata.menuTwo) {
                    this.$confirm('确定删除吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'error'
                    }).then(() => {
                        let data = {
                            id: row.id
                        }
                        deleteAdmin(data).then(res => {
                            if (res.code == 200) {
                                this.$message.success(res.msg)
                                this.getdata(this.pageparm.currentPage)
                            } else {
                                this.$message.error(res.msg);
                            }
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                } else {
                    this.$message({
                        type: 'error',
                        message: '密码错误'
                    });
                }
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });
        },
        // 重置数据
        chongzhi() {
            this.username = ''
            this.mobile = ''
            this.getdata(1)
        },
        // 搜索数据
        search() {
            this.getdata(1);
        },
        // 获取数据
        getdata(page) {
            this.loading = true;
            var parameter = {
                page: (page - 1) * 20,
                username: this.username,
                mobile: this.mobile
            };
            getAdminList(parameter).then((res) => {
                this.loading = false;
                if (res.code != 200) {
                    this.$Message({
                        type: "info",
                        message: res.msg,
                    });
                } else {
                    this.DataList = res.data.list;
                    // this.pageparm.currentPage = page;
                    // this.pageparm.total = res.data.count;
                    return;
                }
            })
        },
    }

}
</script>

<style></style>